<%@page import="java.util.ArrayList"%>
<%@page import="com.tubeonfire.search.admin.TubeSearchModel"%>
<%@page import="com.tubeonfire.entity.Playlist"%>
<%@page import="com.tubeonfire.model.admin.PlaylistModel"%>
<%@page import="java.util.Locale"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="com.tubeonfire.entity.Tube"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	List<Tube> list = new ArrayList<Tube>();
	if(request.getAttribute("result")!=null){
		list = (ArrayList<Tube>)request.getAttribute("result");
	}	
	ImagesService imagesService = ImagesServiceFactory.getImagesService(); 	
	NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); 		
	PlaylistModel plModel = new PlaylistModel();
	plModel.prepareAll(true);	
%>
<jsp:include page="/admin/elements/header.jsp">
	<jsp:param value="Slideshow Manager" name="title"/>
</jsp:include>
<script type="text/javascript" src="/admin/js/mine/slideshow_manager.js"></script>
<script type="text/javascript" src="/admin/js/custom/tables.js"></script>
<script type="text/javascript" src="/admin/js/custom/general.js"></script>
	<body class="loggedin">
		<jsp:include page="/admin/elements/top.jsp"/>
	    <!-- START OF MAIN CONTENT -->
	    <div class="mainwrapper">
	     	<div class="mainwrapperinner">  	     		       	       
				<jsp:include page="/admin/elements/left.jsp">
					<jsp:param value="tube" name="current_page"/>
				</jsp:include>							              	                   
	        	<div class="maincontent noright">
	        		<div class="maincontentinner">	
        				<ul class="maintabmenu">
		                	<li><a href="/admin/youtube/search">Youtube Search</a></li>
		                	<li><a href="/admin/tube/list">Tube Manager</a></li>		
		                	<li class="current"><a href="/admin/tube/slideshow">Slide Show Manager</a></li>		
		                </ul><!--maintabmenu-->	            			               
		                     
	                	<div class="content">	
	                	<jsp:include page="/admin/elements/message.jsp"/>	
	                	<div id="messageDiv" class="notification hidden">						    
						    <p></p>
						</div>	                			                		                	   	                    
	                    	<div class="contenttitle">
	                    		<h2 class="image"><span>List Slideshow Tube</span></h2>
	                    	</div>	                    	
			                <div class="tableoptions">			                	
			                    <select class="radius3 action" id="action">			  
			                    	<option value="0">Select action</option>                  	
			                    	<option value="1">Remove all checked tube from slideshow</option>			                    	
			                    </select> &nbsp;
			                    <button class="radius3" id="applyTube">Apply</button>			                  
			                    <small class="desc" style="float: right;">(Tips)</small>		                    	
			                </div>						                          
		                    <table id="table-result" cellpadding="0" cellspacing="0" border="0" class="stdtable stdtablecb">		                    
			                    <colgroup>
			                        <col class="con0">
			                        <col class="con1">
			                        <col class="con0">
			                        <col class="con1">
			                        <col class="con0">
			                        <col class="con1">
			                        <col class="con0">
			                    </colgroup>
			                    <thead>
			                        <tr>
			                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
			                            <th class="head1">Thumb</th>
			                            <th class="head0">Title</th>
			                            <th class="head1">Playlist</th>
			                            <th class="head0">Duration</th>
			                            <th class="head1">Views</th>
			                          	<th class="head1">Action</th>
			                        </tr>
			                    </thead>
			                    <tfoot>
			                        <tr>
			                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
			                            <th class="head1">Thumb</th>
			                            <th class="head0">Title</th>
			                             <th class="head1">Playlist</th>
			                            <th class="head0">Duration</th>
			                            <th class="head1">Views</th>
			                          	<th class="head1">Action</th>
			                        </tr>
			                    </tfoot>
			                    <tbody id="sortable">
			                    <%
				                	if(list!=null&&list.size()>0){				               								
										for(Tube tube: list){
											Playlist pl = PlaylistModel.byId(tube.getPlaylistId(), true);
											String imgUrl = tube.getImageUrl();
											if(!tube.getImageUrl().contains("http://")){
												try{
													BlobKey blobKey = new BlobKey(imgUrl);
													imgUrl = imagesService.getServingUrl(blobKey);
												}catch(Exception e){
													imgUrl = "/admin/images/tube.png";
												}														
											}											
									%>
				                        <tr id="<%=tube.getId()%>">
				                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=tube.getId()%>"></span></td>
				                            <td class="center">
				                            	<img src="<%=imgUrl %>" alt="" width="100px">
				                            </td>
				                            <td><a href="/video/<%=tube.getId()%>/<%=tube.getAlias()%>.html" target="blank" title="View this tube"><%=tube.getTitle() %></a></td>
				                            <td class="center">
				                            	<%
				                            		if(pl!=null){
				                            		%>
				                            			<a target="blank" href="/admin/playlist/edit?id=<%=pl.getId() %>" title="View <%=pl.getTitle() %> playlist"><%=pl.getTitle() %></a>				                            			
				                            		<%
				                            		}else{
				                            			%>
				                            			<small>Not exists</small>  
				                            			<%
				                            		}
				                            	%>	
				                            </td>
				                            <td class="center"><%=tube.getTotalTime() %></td>
				                            <td class="center"><%=nf.format(tube.getView())%></td>				                           
				                            <td class="center" style="width: 160px">				                            					                            
				                            	<a class="stdbtn <%=pl!=null?"":"btn_red" %>" target="blank" href="/admin/tube/edit?id=<%=tube.getId()%>" id="<%=tube.getId()%>" title="Edit tube information">Edit</a> 
				                            	<a class="btnRemove stdbtn" target="blank" href="<%=tube.getId()%>" title="Remove this tube">Remove</a>					                            	
				                            </td>
				                        </tr>
			                        <%
										}	
				                	}
			                        %>			                        		                       
			                    </tbody>
			                </table>   		                   	                    
	                </div>
	               
	                <!--content-->	                
	            </div><!--maincontentinner-->
				<jsp:include page="/admin/elements/bottom.jsp"></jsp:include>                    	           	
	        </div><!--maincontent-->	                        
	     	</div><!--mainwrapperinner-->
	    </div><!--mainwrapper-->
	    <div id="opacity"></div>
		<img id="image_loadder" src="/admin/images/ajax-loader.gif">   
		<!-- END OF MAIN CONTENT -->    
	</body>
</html>
